package com.example.administrator.shihuo.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.shihuo.R;

/**
 * Created by Sunshine on 2016/5/11.
 */
public class MimelistViewAdapter extends BaseAdapter {
    private String[] names1;
    private String[] names2;
    private LayoutInflater inflater;
    private int type;

    public MimelistViewAdapter(Context context, String[] names1, String[] names2) {
        this.names1 = names1;
        this.names2 = names2;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getItemViewType(int position) {
        if (position < names1.length) {
            type = 0;
        } else if (position == names1.length) {
            type = 1;
        } else {
            type = 2;
        }
        return type;
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getCount() {
        return names1.length + names2.length + 1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        switch (getItemViewType(position)) {
            case 0:
                if (convertView == null) {
                    convertView = inflater.inflate(R.layout.simple_item, parent, false);
                    ImageView imageViewlogo = (ImageView) convertView.findViewById(R.id.header);
                    if (position == 0) {
                        imageViewlogo.setImageResource(R.drawable.shopping);
                    } else if (position == 2) {
                        imageViewlogo.setImageResource(R.drawable.icon_dingdan);
                    } else if (position == 3) {
                        imageViewlogo.setImageResource(R.drawable.icon_qianbao);
                    } else if (position == 4) {
                        imageViewlogo.setImageResource(R.drawable.icon_shoucang);
                    } else if (position == 5) {
                        imageViewlogo.setImageResource(R.drawable.icon_shaiwu);
                    } else if (position == 6) {
                        imageViewlogo.setImageResource(R.drawable.icon_zan);
                    } else {
                        imageViewlogo.setImageResource(R.drawable.icon_dizhi);
                    }
                    TextView textView = (TextView) convertView.findViewById(R.id.name);
                    ImageView imageViewdes = (ImageView) convertView.findViewById(R.id.desc);
                    textView.setText(names1[position]);
                }
                break;
            case 1:
                if (convertView == null) {
                    convertView = inflater.inflate(R.layout.empty_layout, parent, false);
                }
                break;

            case 2:
                if (convertView == null) {
                    convertView = inflater.inflate(R.layout.simple_item, parent, false);
                    ImageView imageViewlogo = (ImageView) convertView.findViewById(R.id.header);
                    if (position == 8) {
                        imageViewlogo.setImageResource(R.drawable.kefu_icon);
                    } else if (position == 9) {
                        imageViewlogo.setImageResource(R.drawable.icon_shezhi);
                    } else {
                        imageViewlogo.setImageResource(R.drawable.icon_banben);
                    }
                    TextView textView = (TextView) convertView.findViewById(R.id.name);
                    ImageView imageViewdes = (ImageView) convertView.findViewById(R.id.desc);
                    textView.setText(names2[position - names1.length - 1]);
                }
                break;
        }

        return convertView;
    }
}
